<?php session_start(); 

    $_SESSION['LOGGED_IN'] = false;
    include "Employee.php";
    include "EmployeeDao.php";
    include "Datasource.php";
    if(isset($_POST['user']) && isset($_POST['pass']))
    {
        //theanykey.db.4987544.hostedresource.com
        $conn = new Datasource("localhost","theanykey","root","");
        //$conn = new Datasource("theanykey.db.4987544.hostedresource.com","theanykey","theanykey","Triumph123");
        $employee = new Employee();
        $employeeDao = new EmployeeDao();
        $employee->setLoginID($_POST['user']);
        $_SESSION['user'] = $_POST['user'];
        $employee->setPassword(md5($_POST['pass']));
        $_SESSION['pass'] = md5($_POST['pass']);
        $results = $employeeDao->searchMatching($conn, $employee);
        if(empty($results) == false)
        {
           $_SESSION['LOGGED_IN'] = true;
           $_SESSION['fail'] = false;
           $_SESSION['userID'] = $results[0]->getEmpID();
           $_SESSION['EMPLAST'] = $results[0]->getLastName();
           $_SESSION['EMPFIRST'] = $results[0]->getFirstName();
           $_SESSION['EMPLOGIN'] = $results[0]->getLoginID();
           $_SESSION['EMPROLE'] = $results[0]->getRole();
        }
        else
        {
            $_SESSION['fail'] = true;
        }
    }
    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Header</title>
    </head>
    <body bgcolor="#454343" onload=failCheck();>
	<body text="#FFFFFF">
	<body link="white" alink="white" vlink="white"> 
        <center>
			<img src="images/Triumph_01.gif" width="1000" height="176" alt="">
            <table width="1000" height="70"  bgcolor='#454343'>
              <tr>
                <?php
                        // put your code here
                            if ($_SESSION['LOGGED_IN'] == true)
                            {
                                print("<td align='left'><input type='button' value='Ticket Menu' onClick=\"parent.main.location='TicketMaintenance.html'\">&nbsp;
                                       <input type='button' value='Maintenance Menu' onClick=\"parent.main.location='MaintenanceMenu.html'\"></td>
                                       <td align='right'><a href='header.php' onClick=\"parent.main.location='ttshome.php'\">Log Out ".$_SESSION['user']."</a></td>");
                            }
                            else
                            {
                                print("<td align='right'><form method='post' action='header.php'>
                                        Username: <input type='text' length='25' label='Username:' id='user' name='user'>
                                        Password: <input type='password' length='25' label='Password:' id='pass' name='pass'>
                                        <input type='submit' label='Login' value='Login'>
                                        </form></td>");

                            }
                        ?>
              </tr>
            </table>
        </center>


    </body>

    <script type='text/javascript'>
        function failCheck()
        {
            if(<?php print $_SESSION['fail'] ?> == true)
            {
                alert("Incorrect Username and Password");
            }
        }
    </script>
</html>

